package com.huabo.audit.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfig;

import com.hbfk.util.JsonBean;
import com.hbfk.util.ResponseFormat;
import com.huabo.audit.oracle.entity.TblAduitProGramEntity;
import com.huabo.audit.oracle.entity.TblNbsjAdvicenoteEntity;
import com.huabo.audit.oracle.entity.TblNbsjProjectDataEntity;
import com.huabo.audit.oracle.vo.DataProVo;
import com.huabo.audit.oracle.vo.TblNbsjAdvicenoteVo;
import com.huabo.audit.oracle.vo.TblnbsjProjectVo;
import com.huabo.audit.service.ActivityPluginsService;
import com.huabo.audit.service.AttachmentService;
import com.huabo.audit.service.ProcessService;
import com.huabo.audit.service.TblAduitProGramService;
import com.huabo.audit.service.TblAttachmentService;
import com.huabo.audit.service.TblNbsjAdvicenoteService;
import com.huabo.audit.service.TblNbsjAuditplanService;
import com.huabo.audit.service.TblNbsjFactbookService;
import com.huabo.audit.service.TblNbsjOperateService;
import com.huabo.audit.service.TblNbsjProjectDataProService;
import com.huabo.audit.service.TblNbsjProjectService;
import com.huabo.audit.service.TblNbsjSheetService;
import com.huabo.audit.util.FileUtil;
import com.huabo.audit.util.FreeMarkerUtil;
import com.huabo.audit.util.R;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;

/**
 * 审计准备阶段
 */
@RestController
@Slf4j
@Api(value = "审计准备阶段", tags = {"审计准备阶段接口"})
@RequestMapping(value = "/auditReady")
public class NbsjReadyController {
	
	@Resource
	public TblAduitProGramService tblAduitProGramService;
	
	@Resource
	public TblNbsjProjectService tblnbsjProjectService;
	
	@Resource
	public TblNbsjProjectDataProService dataProService;
	
	@Resource
	public AttachmentService attachmentService;
	
	@Resource
	public ActivityPluginsService activityPluginsService;
	
	@Resource
	public TblNbsjAdvicenoteService tblNbsjAdvicenoteService;
	
	@Resource
	public ProcessService processService;
	
	@Resource
	public TblNbsjSheetService tBlNbsjSheetService;
	
	@Resource
	public TblNbsjFactbookService tblNbsjFactbookService;
	
	@Resource
    public TblNbsjAuditplanService tblNbsjAuditplanService;
	
	@Resource
	public TblNbsjOperateService tblNbsjOperateService;
	
	@Resource
	private TblAttachmentService tblAttachmentService;
	
	@Resource
	public FreeMarkerConfig freeMarkerConfig;
	
	
	
	/**
     * 审计指引-左侧树菜单
     */
	@GetMapping("/sjgj/getTreeZy")
	@ApiOperation(value = "审计指引-左侧树菜单")
	public JsonBean getTreeZy(HttpServletRequest request,
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "nodeId", value = "", required = false) @RequestParam(value = "nodeId", required = false) Integer nodeId,
			@ApiParam(name = "tempId", value = "", required = false) @RequestParam(value = "tempId", required = false) Integer tempId,
			@ApiParam(name = "type", value = "mb,fp(审计指引传mb)", required = false) @RequestParam(value = "type", required = false) String type) {
		JsonBean jsonBean = null;
		try {
			jsonBean = tblNbsjOperateService.getTreeZy(token, tempId, nodeId, type);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	
	/**
	 * 审计指引列表
	 */
	@GetMapping("/sjyj/def_cat_list_zy")
	@ApiOperation(value = "审计指引列表")
	public JsonBean def_cat_list_zy(HttpServletRequest request,
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "pageNumber", value = "分页当前页数", required = false) @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
			@ApiParam(name = "pageSize", value = "每页记录数", required = false) @RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
			@ApiParam(name = "tempId", value = "", required = false) @RequestParam(value = "tempId", required = false) Integer tempId,
			@ApiParam(name = "targetId", value = "", required = false) @RequestParam(value = "targetId", required = false) Integer targetId,
			@ApiParam(name = "projectId", value = "", required = false) @RequestParam(value = "projectId", required = false) Integer projectId) {

		JsonBean jsonBean = null;
		try {
			jsonBean = tblAduitProGramService.defZyPageList(token, pageNumber, pageSize,tempId,targetId,projectId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
    @RequestMapping(value = "/getAuditPlanApprovalInfo", produces = "application/json; charset=utf-8", method = {RequestMethod.GET})
	@ApiOperation(value = "审计计划管理-办理审计计划流程页面数据获取页面")
    public JsonBean getAuditPlanApprovalInfo(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="planId",value="审计计划主键 ",required=true) @RequestParam(value = "planId", required = true) Integer planId,
    		@ApiParam(name="taskId",value="工作流任务主键 ",required=true) @RequestParam(value = "taskId", required = true) String taskId,
    		@ApiParam(name="cyId",value="审批记录主键 ",required=true) @RequestParam(value = "cyId", required = true) Integer cyId) {
    	JsonBean jsonBean = null;
		try {
			jsonBean = this.tblNbsjAuditplanService.getAuditPlanApprovalInfo(token,planId,taskId,cyId);
		} catch (Exception e) {
			ResponseFormat.retParam(1,1000,e.getMessage());
		}
		return jsonBean;
    }
    
    
    @RequestMapping(value = "/dealAuditPlanApporvalInfo", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation(value = "审计计划管理-办理审批流程，通过或驳回")
	public JsonBean dealAuditPlanApporvalInfo(HttpServletRequest request,HttpServletResponse response,
			@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
			@ApiParam(name="cyId",value="审批记录主键 ",required=true) @RequestParam(value = "cyId", required = true) Integer cyId,
			@ApiParam(name="taskId",value="工作流任务主键 ",required=true) @RequestParam(value = "taskId", required = true) String taskId,
			@ApiParam(name="planId",value="升级计划主键 ",required=true) @RequestParam(value = "planId", required = true) String planId,
			@ApiParam(name="transition",value="办理结果 通过或驳回 同意或修改 ",required=true) @RequestParam(value = "transition", required = true) String transition,
			@ApiParam(name="optDesc",value="审批意见",required=true) @RequestParam(value = "optDesc", required = true) String optDesc) {
    	
    	JsonBean jsonBean = null;
		try {
			jsonBean = this.tblNbsjAuditplanService.dealAuditPlanApporvalInfo(token,cyId,taskId,transition,optDesc,planId);
		} catch (Exception e) {
			ResponseFormat.retParam(1,1000,e.getMessage());
		}
		return jsonBean;
	}
	/**
	 * 审计指引-新增与修改
	 */
	@RequestMapping(value = "/sjyj/def_cat_add", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "审计指引-新增与修改")
    public JsonBean def_cat_add(HttpServletRequest request,@ApiParam(name="apg",value="实体",required=true)TblAduitProGramEntity apg,
			 @ApiParam(name="token",value="登录用户token",required=false) @RequestHeader("token")String token)throws Exception{
		JsonBean jsonBean = null;
		try {
			jsonBean = this.tblAduitProGramService.defCatAdd(apg,token);
		} catch (Exception e) {
			ResponseFormat.retParam(1,1000,e.getMessage());
		}
		return jsonBean;
    }
	/**
	 * 审计指引-删除
	 */
	@GetMapping("/sjyj/def_cat_del")
	@ApiOperation(value = "审计指引-删除")
    public JsonBean def_cat_del(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="programId",value="主键",required=true)@RequestParam(value = "programId", required = true) Integer programId) {
        
        try {
			return tblAduitProGramService.defCatDel(programId, token);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return null;
    }
	
	/**
     * 审计指引 详情
     */
    @GetMapping("/sjss/def_cat_detail_zy")
    @ApiOperation(value = "审计指引--详情")
    public JsonBean def_cat_detail_zy(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="programid",value="主键",required=true)@RequestParam(value = "programid", required = true) Integer programid) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean = tblAduitProGramService.findDefZyDetail(token,programid);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
    /**
     * 审计指引 左侧树
     */
    @GetMapping("/sjyj/def_left_tree_zy")
    @ApiOperation(value = "审计指引左侧树")
	public JsonBean def_left_tree_zy(HttpServletRequest request, 
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) {

		JsonBean jsonBean = null;
		try {
			jsonBean = tblAduitProGramService.defZyLeftTreeList(token);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
    
    
    /**
     * 审计通知书列表
     */
    @GetMapping("/sjzb/notice_list")
    @ApiOperation(value = "审计通知书列表")
	public JsonBean notice_list(HttpServletRequest request,TblNbsjAdvicenoteVo tblNbsjAdvicenoteVo,
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "pageNumber", value = "分页当前页数", required = false) @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
			@ApiParam(name = "pageSize", value = "每页记录数", required = false) @RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize) {

		JsonBean jsonBean = null;
		try {
			jsonBean = tblNbsjAdvicenoteService.noticePageList(token, pageNumber, pageSize,tblNbsjAdvicenoteVo);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
    
	/**
     * 审计通知书 详情
     */
    @GetMapping("/sjzb/notice_disp")
    @ApiOperation(value = "审计指引--详情")
    public JsonBean notice_disp(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="adviceid",value="主键",required=true)@RequestParam(value = "adviceid", required = true) Integer adviceid) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean = tblNbsjAdvicenoteService.findNoticeDetail(token,adviceid);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
    /**
	 * 审计通知书-新增与修改
	 */
	@RequestMapping(value = "/sjzb/notice_add", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "审计通知书-新增与修改")
    public JsonBean nkgj_projectdp_add(HttpServletRequest request,@ApiParam(name="notice",value="实体",required=true)TblNbsjAdvicenoteEntity notice,
			 @ApiParam(name="token",value="登录用户token",required=false) @RequestHeader("token")String token,
			 @ApiParam(name="attids",value="附件id数组",required=false)String attids)throws Exception{
		JsonBean jsonBean = null;
		try {
			jsonBean = this.tblNbsjAdvicenoteService.noticeAdd(notice,token,attids);
		} catch (Exception e) {
			e.printStackTrace();
			ResponseFormat.retParam(1,1000,e.getMessage());
		}
		return jsonBean;
    }
    /**
     * 审计通知书-导出
     * @param request
     * @param response
     * @param id
     * @throws Exception
     */
    @RequestMapping(value = "/expOuterRuleFile", produces = "application/json; charset=utf-8", method = {RequestMethod.GET})
   	@ApiOperation(value = "审计通知书-导出")
    @ApiOperationSupport(order = 40)
	public void expOuterRuleFile(HttpServletRequest request, HttpServletResponse response,
			@ApiParam(name="adviceid",value="主键",required=true) @RequestHeader("adviceid")String adviceid)throws Exception{
		Map<String, String> map = new HashMap<String,String>();
    	TblNbsjAdvicenoteEntity info = tblNbsjAdvicenoteService.findById(Integer.parseInt(adviceid));
		map.put("repdesc", info.getContent());
		String fileName =info.getAdvicename()+".doc";
		String FREEMARKER_PATH = request.getSession().getServletContext().getRealPath("/template/doc");
		Boolean flag =(Boolean)FreeMarkerUtil.htmlFileHasExist(request, FREEMARKER_PATH, fileName).get("exist");
		if(!flag){//如何静态文件不存在，重新生成
			FreeMarkerUtil.createHtml(freeMarkerConfig, "static.ftl", request, map, FREEMARKER_PATH, fileName);//根据模板生成静态页面
		}
		String fileName1 = FREEMARKER_PATH +"/"+ fileName;
		FileUtil.downLoad(fileName1, response, false, fileName);
		FileUtil.deleteFile(fileName);
	}
	/**
	 * 审计通知书-附件列表
	 */
    @GetMapping("/sjzb/notice_file_list")
	@ApiOperation(value = "工作日志-附件列表")
	public JsonBean notice_file_list(HttpServletRequest request, 
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "adviceid", value = "业务主键", required = true) @RequestParam(value = "adviceid", required = true) Integer adviceid) {

		JsonBean jsonBean = null;
		try {
			jsonBean = this.tblAttachmentService.noticeFileList(token,adviceid);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
    /**
     * 审计通知书-附件删除
     */
    @GetMapping("/sjzb/notice_file_del")
    @ApiOperation(value = "审计通知书-附件删除")
    public R notice_file_del(HttpServletRequest request, HttpServletResponse response,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="attId",value="附件主键ID",required=true) @RequestParam("attId") String attId) throws Exception {
    	return this.tblNbsjAdvicenoteService.removeAttInfoByAttId(token, attId);
    }
	
	/**
	 * 审计通知书-删除
	 */
	@GetMapping("/sjzb/notice_del")
	@ApiOperation(value = "审计通知书-删除")
    public JsonBean notice_del(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="adviceid",value="主键",required=true)@RequestParam(value = "adviceid", required = true) Integer adviceid) {
        
        try {
			return tblNbsjAdvicenoteService.noticeDelete(adviceid, token);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return null;
    }
	
	/**
	 * 审计通知书-作废
	 */
	@GetMapping("/sjzb/notice_cancel")
	@ApiOperation(value = "审计通知书-作废")
    public JsonBean notice_cancel(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="adviceid",value="主键",required=true)@RequestParam(value = "adviceid", required = true) Integer adviceid) {
        
        try {
			return tblNbsjAdvicenoteService.noticeCancel(adviceid, token);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return null;
    }
 
 
    /**
     * 项目资料准备
     * /sjzl/data_list
     */
	@GetMapping("/sjzl/dataproject_list")
	@ApiOperation(value = "项目资料准备列表")
	public JsonBean dataproject_list(HttpServletRequest request, 
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,DataProVo dataProVo,
			@ApiParam(name = "pageNumber", value = "分页当前页数", required = false) @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
			@ApiParam(name = "pageSize", value = "每页记录数", required = false) @RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
			@ApiParam(name = "orgid", value = "orgid", required = false) @RequestParam(value = "orgid", required = false) Integer orgid) {

		JsonBean jsonBean = null;
		try {
			jsonBean = dataProService.dataproPageList(token, pageNumber, pageSize,dataProVo,orgid);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	/**
     * 项目资料准备 预览
     */
    @GetMapping("/sjzl/dataproject_view")
    @ApiOperation(value = "项目资料准备--预览")
    public JsonBean dataproject_view(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="dataId",value="主键",required=true)@RequestParam(value = "dataId", required = true) Integer dataId) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean = dataProService.findDataProDetail(token,dataId);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
    /**
	 * 项目资料准备-新增与修改
	 */
	@RequestMapping(value = "/sjzl/dataproject_save", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "项目资料准备-新增与修改")
    public JsonBean dataproject_save(HttpServletRequest request,@ApiParam(name="notice",value="实体",required=true)TblNbsjProjectDataEntity pd,
			 @ApiParam(name="token",value="登录用户token",required=false) @RequestHeader("token")String token,
			 @ApiParam(name="attids",value="附件id数组",required=false)String attids)throws Exception{
		JsonBean jsonBean = null;
		try {
			jsonBean = this.dataProService.dataproAdd(pd,token,attids);
		} catch (Exception e) {
			ResponseFormat.retParam(1,1000,e.getMessage());
		}
		return jsonBean;
    }
	/**
	 * 项目资料准备-附件列表
	 */
    @GetMapping("/sjzl/dataproject_file_list")
	@ApiOperation(value = "项目资料准备-附件列表")
	public JsonBean dataproject_file_list(HttpServletRequest request, 
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "dataId", value = "业务主键", required = true) @RequestParam(value = "dataId", required = true) Integer dataId) {
		JsonBean jsonBean = null;
		try {
			jsonBean = this.tblAttachmentService.dataprojectFileList(token,dataId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
    /**
     * 项目资料准备-附件删除
     */
    @GetMapping("/sjzl/dataproject_file_del")
    @ApiOperation(value = "项目资料准备-附件删除")
    public R report_file_del(HttpServletRequest request, HttpServletResponse response,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="attId",value="附件主键ID",required=true) @RequestParam("attId") String attId) throws Exception {
    	return this.dataProService.removeAttInfoByAttId(token, attId);
    }
	
	/**
	 * 项目资料准备-删除
	 */
	@GetMapping("/sjzl/dataproject_del")
	@ApiOperation(value = "项目资料准备-删除")
    public JsonBean dataproject_del(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="dataId",value="主键",required=true)@RequestParam(value = "dataId", required = true) Integer dataId) {
        
        try {
			return dataProService.dataproDelete(dataId, token);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return null;
    }
    
	
	/**
	 * 前期审计资料列表
	 */
	@GetMapping("/sjzb/project_proposal_yw")
	@ApiOperation(value = "前期审计资料列表")
	public JsonBean project_proposal_yw(HttpServletRequest request, TblnbsjProjectVo tblnbsjProjectVo,
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "pageNumber", value = "分页当前页数", required = false) @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
			@ApiParam(name = "pageSize", value = "每页记录数", required = false) @RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize) {

		JsonBean jsonBean = null;
		try {
			jsonBean = tblnbsjProjectService.projectProposalPageList(token, pageNumber, pageSize,tblnbsjProjectVo);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	@GetMapping("/sjzb/project_proposal_detail")
	@ApiOperation(value = "前期审计资料--明细")
    public JsonBean project_proposal_detail(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="projectId",value="主键",required=true)@RequestParam(value = "projectId", required = true) Integer projectId) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean = tblnbsjProjectService.findProjectProposalDetail(token,projectId);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
	
	/**
	 * 前期审计资料--导入资料列表
	 */
	@GetMapping("/sjgd/audit_plan_list_planId_in")
	@ApiOperation(value = "前期审计资料--导入资料列表")
	public JsonBean audit_plan_list_planId_in(HttpServletRequest request,
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "pageNumber", value = "分页当前页数", required = false) @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
			@ApiParam(name = "pageSize", value = "每页记录数", required = false) @RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
			@ApiParam(name = "projectname", value = "项目名称", required = false) @RequestParam(value = "projectname", required = false) String projectname) {

		JsonBean jsonBean = null;
		try {
			jsonBean = tblnbsjProjectService.auditPlanListPlanIdIn(token, pageNumber, pageSize,projectname);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	/**
	 * 前期审计资料--导入资料选择保存
	 */
	@RequestMapping(value = "/sjgd/audit_plan_list_planId_in_save", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "前期审计资料--导入资料选择保存")
    public JsonBean audit_plan_list_planId_in_save(HttpServletRequest request,
			 @ApiParam(name="token",value="登录用户token",required=false) @RequestHeader("token")String token,
			 @ApiParam(name="ids",value="选择导入的项目ids(,分隔)",required=false)String ids)throws Exception{
		JsonBean jsonBean = null;
		try {
			jsonBean = this.tblnbsjProjectService.auditPlanInAdd(ids,token);
		} catch (Exception e) {
			ResponseFormat.retParam(1,1000,e.getMessage());
		}
		return jsonBean;
    }
	
	
	
	
    
    
    
    
    
    
    
	/*
	/**
     * 模板管理--列表
     *
     * @return
     
    @RequestMapping(value = "/sjyj/t03_rules_edit_list")
    public ModelAndView t03_rules_edit_list(String templeteName, String templeteCode, Integer pageNumber) {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("nbsj/sjyj/t03_rules_edit_list");
        return mv;
    }
    /**
     * 模板管新建
     
    @RequestMapping(value = "/sjyj/t03_rules_add_list")
    public ModelAndView t03_rules_add_list() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("nbsj/sjyj/t03_rules_add_list");
        return mv;
    }
    /**
     * 审计模板--入口
     *
     * @param tempId
     
    @RequestMapping(value = "/sjyj/index")
    public ModelAndView sjyj_index(String tempId, String type,HttpServletRequest request) {
        ModelAndView mv = new ModelAndView();
        mv.addObject("tempId", tempId);
        mv.addObject("sjzb", false);
        mv.addObject("type", type);
        String status = request.getParameter("status");
        mv.addObject("status", status);
		String cz = request.getParameter("cz");
		mv.addObject("cz", cz);
		String flview = request.getParameter("flview");
		mv.addObject("flview", flview);
        //查询框代码
		String choiceSearch = request.getParameter("choiceSearch");
		if(choiceSearch == null || "".equals(choiceSearch)) {
			choiceSearch = "hide";
		}
		mv.addObject("choiceSearch",choiceSearch);
		mv.addObject("isuse", request.getParameter("isuse"));
        mv.setViewName("nbsj/sjyj/def_tmpl_index");
        mv.addObject("cz", request.getParameter("cz"));
        return mv;
    }
    /**
     * 审计指引
     
    @RequestMapping(value = "/sjyj/index_zy")
    public ModelAndView sjyj_index_zy(String tempId, String type,HttpServletRequest request) {
        ModelAndView mv = new ModelAndView();
        mv.addObject("tempId", tempId);
        mv.addObject("sjzb", false);
        mv.addObject("type", type);
        String status = request.getParameter("status");
        mv.addObject("status", status);
        mv.addObject("cz", request.getParameter("cz"));
        mv.addObject("flview", request.getParameter("flview"));
		mv.addObject("isuse", request.getParameter("isuse"));
        //查询框代码
		String choiceSearch = request.getParameter("choiceSearch");
		if(choiceSearch == null || "".equals(choiceSearch)) {
			choiceSearch = "hide";
		}
		mv.addObject("choiceSearch",choiceSearch); 	
        mv.setViewName("nbsj/sjyj/def_tmpl_index_zy");
        return mv;
    }
    /**
     * 审计模板--头信息
     *
     
    @RequestMapping(value = "/sjyj/def_head")
    public ModelAndView sjyj_def_head(String tempId, String type,HttpServletRequest request) {
		ModelAndView mv = new ModelAndView();
		mv.addObject("tempId", tempId);
		mv.addObject("type", type);
		String flview = request.getParameter("flview");
		mv.addObject("flview", flview);
		mv.addObject("isuse", request.getParameter("isuse"));
		mv.setViewName("nbsj/sjyj/def_head");
		return mv;
    }
    /**
     * 审计指引   --头信息
     
    @RequestMapping(value = "/sjyj/def_head_zy")
    public ModelAndView sjyj_def_head_zy(String tempId, String type) {
        ModelAndView mv = new ModelAndView();
        mv.addObject("tempId", tempId);
        mv.addObject("type", type);
        mv.setViewName("nbsj/sjyj/def_head_zy");
        return mv;
    }
    /**
     * 审计模板--树形
     *
     
    @RequestMapping(value = "/sjyj/def_left_tree")
    public ModelAndView sjyj_def_left_tree(BigDecimal tempId, String type,HttpServletRequest request) {
        ModelAndView mv = new ModelAndView();
        // TblNbsjTemplete tblNbsjTemplete =
        // this.tblNbsjTempleteService.get(tempId);
        mv.addObject("tempId", tempId);
        mv.addObject("type", type);
        // mv.addObject("tblNbsjTemplete", tblNbsjTemplete);
        mv.addObject("status", request.getParameter("status"));
        mv.addObject("cz", request.getParameter("cz"));
		mv.addObject("flview", request.getParameter("flview"));
		mv.addObject("isuse", request.getParameter("isuse"));
        //查询框代码
		String choiceSearch = request.getParameter("choiceSearch");
		if(choiceSearch == null || "".equals(choiceSearch)) {
			choiceSearch = "hide";
		}
		mv.addObject("choiceSearch",choiceSearch); 
        mv.setViewName("nbsj/sjyj/def_left_tree");
        return mv;
    }
    /**
     * 审计指引   --树形
     
    @RequestMapping(value = "/sjyj/def_left_tree_zy")
    public ModelAndView sjyj_def_left_tree_zy(BigDecimal tempId, String type,HttpServletRequest request) {
        ModelAndView mv = new ModelAndView();
        // TblNbsjTemplete tblNbsjTemplete =
        // this.tblNbsjTempleteService.get(tempId);
        mv.addObject("tempId", tempId);
        mv.addObject("type", type);
        String status = request.getParameter("status");
        String sjzb = request.getParameter("sjzb");
        mv.addObject("sjzb", sjzb);
        mv.addObject("status", status);
        mv.addObject("cz", request.getParameter("cz"));
        // mv.addObject("tblNbsjTemplete", tblNbsjTemplete);
        mv.addObject("flview", request.getParameter("flview"));
        mv.addObject("isuse", request.getParameter("isuse"));
		String choiceSearch = request.getParameter("choiceSearch");
		if(choiceSearch == null || "".equals(choiceSearch)) {
			choiceSearch = "hide";
		}
		mv.addObject("choiceSearch",choiceSearch); 
        mv.setViewName("nbsj/sjyj/def_left_tree_zy");
        return mv;
    }
    /**
     * 获取树形数据
     
    @RequestMapping(value = "/sjgj/getTree", produces = "application/json; charset=utf-8")
    public
    @ResponseBody
    String jkzx_gzjfindOrganizationByTree(BigDecimal nodeId, String type, BigDecimal tempId, HttpServletRequest request) {
        String url = "";
        //String status = request.getParameter("status");
        String cz = request.getParameter("cz");
        String flview = request.getParameter("flview");
        String isuse = request.getParameter("isuse");
        //查询框代码
		String choiceSearch = request.getParameter("choiceSearch");
        if (StringUtils.isNotBlank(type)) {
            switch (type) {
                // 模板
                case "mb":
                    url = "/nbsj/sjyj/def_cat_list?1=1&cz="+cz+"&flview="+flview+"&isuse="+isuse+"&choiceSearch="+choiceSearch;
                    break;
                // 分配
                case "fp":
                    url = "/nbsj/jsfp/def_cat_list?1=1&cz="+cz+"&choiceSearch="+choiceSearch+"&choiceSearch="+choiceSearch;
                    break;
                default:
                    break;
            }
        }
//		if (status != null && status.equals("0")) {
//			if (null == nodeId) {
//				List<Tree> tree = this.tblTargetTypeService.getRootMb(tempId, "/nbsj/sjyj/def_cat_list?1=1");
//				return JSONObject.toJSONString(tree);
//			} else {
//				List<Tree> list = this.tblTargetTypeService.getTreeMb(nodeId, tempId, url);
//				return JSONObject.toJSONString(list);
//			}
//		} else {
        if (null == nodeId) {
            List<Tree> tree = this.tblTargetTypeService.getRoot(tempId, url);//"/nbsj/sjyj/def_cat_list?1=1&cz="+cz
            return JSONObject.toJSONString(tree);
        } else {
            List<Tree> list = this.tblTargetTypeService.getTree(nodeId, tempId, url);
            return JSONObject.toJSONString(list);
        }
    }
    /**
     * 获取树形数据
     
    @RequestMapping(value = "/sjgj/getTreeZy", produces = "application/json; charset=utf-8")
    public
    @ResponseBody
    String jkzx_gzjfindOrganizationByTreeZy(BigDecimal nodeId, String type, BigDecimal tempId, HttpServletRequest request) {
    	String url = "";
    	//String status = request.getParameter("status");
    	String cz = request.getParameter("cz");
    	String flview = request.getParameter("flview");
    	String isuse = request.getParameter("isuse");
        //查询框代码
		String choiceSearch = request.getParameter("choiceSearch");
    	if (StringUtils.isNotBlank(type)) {
    		switch (type) {
    		// 模板
    		case "mb":
    			url = "/nbsj/sjyj/def_cat_list_zy?1=1&cz="+cz+"&flview="+flview+"&isuse="+isuse+"&choiceSearch="+choiceSearch;
    			break;
    			// 分配
    		case "fp":
    			url = "/nbsj/jsfp/def_cat_list_zy?1=1&cz="+cz+"&choiceSearch="+choiceSearch;
    			break;
    		default:
    			break;
    		}
    	}
//		if (status != null && status.equals("0")) {
//			if (null == nodeId) {
//				List<Tree> tree = this.tblTargetTypeService.getRootMb(tempId, "/nbsj/sjyj/def_cat_list?1=1");
//				return JSONObject.toJSONString(tree);
//			} else {
//				List<Tree> list = this.tblTargetTypeService.getTreeMb(nodeId, tempId, url);
//				return JSONObject.toJSONString(list);
//			}
//		} else {
    	if (null == nodeId) {
    		List<Tree> tree = this.tblTargetTypeService.getRoot(tempId, url);//"/nbsj/sjyj/def_cat_list?1=1&cz="+cz
    		return JSONObject.toJSONString(tree);
    	} else {
    		List<Tree> list = this.tblTargetTypeService.getTree(nodeId, tempId, url);
    		return JSONObject.toJSONString(list);
    	}
    }
    /**
     * 审计模板--树形新增
     
    @RequestMapping(value = "/sjyj/audit_type_add")
    public ModelAndView audit_type_add(BigDecimal tempId, BigDecimal parentId,HttpServletRequest request) {
        ModelAndView mv = new ModelAndView();
        mv.addObject("tempId", tempId);
        String status = request.getParameter("status");
        mv.addObject("parentId", parentId);
        mv.addObject("status", status);
        //查询框代码
		String choiceSearch = request.getParameter("choiceSearch");
		if(choiceSearch == null || "".equals(choiceSearch)) {
			choiceSearch = "hide";
		}
		mv.addObject("choiceSearch",choiceSearch); 		
        mv.setViewName("nbsj/sjgj/audit_type_add");
        return mv;
    }
    /**
     * 审计模板--修改跳转
     
    @RequestMapping(value = "/sjyj/audit_type_update")
    public ModelAndView audit_type_update(BigDecimal tempId, BigDecimal nodeId,HttpServletRequest request) {
        ModelAndView mv = new ModelAndView();
        TblTargetTypeEntity targetType = this.tblTargetTypeService.getById(nodeId);
        if (null != targetType) {
            mv.addObject("target", targetType);
        }
        mv.addObject("tempId", tempId);
        mv.addObject("parentId", nodeId);
        //查询框代码
		String choiceSearch = request.getParameter("choiceSearch");
		if(choiceSearch == null || "".equals(choiceSearch)) {
			choiceSearch = "hide";
		}
		mv.addObject("choiceSearch",choiceSearch); 			
        mv.setViewName("nbsj/sjgj/audit_type_add");
        return mv;
    }
    /**
     * 保存树形
     
    @RequestMapping(value = "/sjyj/audit_type_save")
    public
    @ResponseBody
    String audit_type_save(BigDecimal tempId, BigDecimal parentId, String targetName, String targetDesc, BigDecimal targetId,HttpServletRequest request) {
        TblNbsjTempleteEntity nbsjTemplete = this.tblNbsjTempleteService.getById(tempId);
        String status = request.getParameter("status");
        if (null != nbsjTemplete) {
            if (null == targetId) {
                TblTargetTypeEntity targetType = new TblTargetTypeEntity();
                targetType.setParentId(parentId);
                targetType.setNbsjTemplete(nbsjTemplete);
                targetType.setTargetName(targetName);
                targetType.setTargetDesc(targetDesc);
                if (status != null && status.trim().length() > 0) {
                    targetType.setStatus(Integer.parseInt(status));
                }
                this.tblTargetTypeService.save(targetType);
            } else {
                TblTargetTypeEntity targetType = this.tblTargetTypeService.getById(targetId);
                if (null != targetType) {
                    targetType.setParentId(targetType.getParentId());
                    targetType.setNbsjTemplete(nbsjTemplete);
                    targetType.setTargetName(targetName);
                    targetType.setTargetDesc(targetDesc);
                    if (status != null && status.trim().length() > 0) {
                        targetType.setStatus(Integer.parseInt(status));
                    }
                    this.tblTargetTypeService.merge(targetType);
                } else {
                    return JsonBean.error("保存失败！");
                }
            }
//            logger.info("保存审计目标成功！");
            return JsonBean.success();
        }
//        logger.info("保存审计目标失败！");
        return JsonBean.error("保存失败！");
    }
    /**
     * 审计目标--删除
     
    @RequestMapping(value = "/sjyj/audit_type_del", produces = "application/json; charset=utf-8")
    public
    @ResponseBody
    String audit_type_save(BigDecimal tempId, BigDecimal targetId) {
        TblTargetTypeEntity targetType = this.tblTargetTypeService.getById(targetId);
        if (null != targetType) {
            int count = this.tblTargetTypeService.getCount(tempId, targetId);
            if (count == 0) {
                this.tblAduitProGramService.deleteByTargetId(targetId.intValue());
                this.tblTargetTypeService.delete(targetType);
                return JsonBean.success();
            }
            return JsonBean.error("请先删除子集节点！");
        }
        return JsonBean.error();
    }
    /**
     * 审计模板--列表
     
    @RequestMapping(value = "/sjyj/def_cat_list")
    public ModelAndView sjyj_def_cat_list(BigDecimal targetId, BigDecimal tempId, Integer pageNumber, String type,HttpServletRequest request) {
        ModelAndView mv = new ModelAndView();
        String status = request.getParameter("status");
//		if (status != null && status.equals("0")) {
//			pageBean = this.tblAduitProGramService.findByTargetIdMb(targetId, tempId, pageNumber, pageBean.getPageSize());
//		} else {
        pageBean = this.tblAduitProGramService.findByTargetId(targetId.intValue(), tempId.intValue(), pageNumber.intValue(), pageBean.getPageSize());
        //}
		mv.addObject("pageBean", pageBean);
		mv.addObject("targetId", targetId);
		mv.addObject("type", type);
		mv.addObject("status", status);
		mv.addObject("flview", request.getParameter("flview"));
		mv.addObject("cz", request.getParameter("cz"));
		mv.addObject("isuse", request.getParameter("isuse"));
		mv.addObject("tempId", tempId);
        //查询框代码
		String choiceSearch = request.getParameter("choiceSearch");
		if(choiceSearch == null || "".equals(choiceSearch)) {
			choiceSearch = "hide";
		}
		mv.addObject("choiceSearch",choiceSearch); 			
		mv.setViewName("nbsj/sjyj/def_cat_list");
        return mv;
    }
    /**
     * 审计指引---列表
     
    @RequestMapping(value = "/sjyj/def_cat_list_zy")
    public ModelAndView sjyj_def_cat_list_zy(BigDecimal targetId, BigDecimal tempId, Integer pageNumber, String type,HttpServletRequest request) {
        ModelAndView mv = new ModelAndView();
		String status = request.getParameter("status");
		String view = request.getParameter("view");
		String flview = request.getParameter("flview");
		String cz = request.getParameter("cz");
//		if (status != null && status.equals("0")) {
//			pageBean = this.tblAduitProGramService.findByTargetIdMb(targetId, tempId, pageNumber, pageBean.getPageSize());
//		} else {
        pageBean = this.tblAduitProGramService.findByTargetId(targetId.intValue(), tempId.intValue(), pageNumber.intValue(), pageBean.getPageSize());
        //}
		mv.addObject("pageBean", pageBean);
		mv.addObject("targetId", targetId);
		mv.addObject("tempId", tempId);
		mv.addObject("type", type);
		mv.addObject("status", status);
		mv.addObject("view",view);
		mv.addObject("flview",flview);
		mv.addObject("cz", cz);
		mv.addObject("isuse", request.getParameter("isuse"));
        //查询框代码
		String choiceSearch = request.getParameter("choiceSearch");
		if(choiceSearch == null || "".equals(choiceSearch)) {
			choiceSearch = "hide";
		}
		String sjzb = request.getParameter("sjzb");
		 mv.addObject("sjzb", sjzb);
		mv.addObject("choiceSearch",choiceSearch); 			
		mv.setViewName("nbsj/sjyj/def_cat_list_zy");
        return mv;
    }
    
    /**
     *  审计项目资料
     * @return
     
    @RequestMapping(value="/sjzl/data_list")
    public ModelAndView data_list(HttpServletRequest request) {
    	  TblNbsjProjectEntity project = this.tblnbsjProjectService.getSelectProject();
          ModelAndView mv = new ModelAndView();
          if (project != null) {
        	  	TblOrganization attribute1 = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");// 当前用户的机构
	          	mv.addObject("orgid", attribute1.getOrgid());
	          	mv.setViewName("/nbsj/sjzb/data_project");
          } else {
              	setErrorJsp("001",request);
              	mv.setViewName("nbsj/main41");
          }
          return mv;
	}
    /**
     *  审计项目资料
     * @return
     
    @RequestMapping(value="/sjzl/dataproject_list")
    public ModelAndView dataproject_list(Integer pageNumber,TblProjectDataPreEntity dataPre,String orgid,HttpServletRequest request) {
		ModelAndView mv=new   ModelAndView();
		if(orgid==null || orgid=="") {
			TblOrganization attribute = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");// 选则的机构
			orgid=attribute.getOrgid().toString();
		}
		PageBean projectDataList = dataProService.projectDataList(pageNumber, pageBean.getPageSize(), dataPre, orgid);
		mv.addObject("pageBean", projectDataList);
		mv.addObject("orgid", orgid);
		mv.addObject("dataPre", dataPre);
		mv.setViewName("/nbsj/sjzb/projectDataPre_list");
		//查询框代码
		String choiceSearch = request.getParameter("choiceSearch");
		if(choiceSearch == null || "".equals(choiceSearch)) {
			choiceSearch = "hide";
		}
		mv.addObject("choiceSearch",choiceSearch); 
		return mv;
    	
    	
	}
    
    /**
     *  审计项目资料
     * @return
     
    @RequestMapping(value = "/sjzl/dataproject_left")
	public ModelAndView dataproject_left(HttpServletRequest request) {
		TblOrganization organization = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");
		ModelAndView mv = new ModelAndView("nbsj/sjzb/dataproject_left");
		mv.addObject("orgid", organization.getOrgid());
		mv.addObject("treeName", organization.getOrgname());
		String type = request.getParameter("type");
		mv.addObject("type", type);
		return mv;
	}
    
    /**
     *  审计项目资料
     * @return
     
    @RequestMapping(value="/sjzl/dataproject_save_view")
    public ModelAndView dataproject_add_view(String orgid,HttpServletRequest request){
    	ModelAndView mv=new   ModelAndView();
    	TblNbsjProjectEntity project = this.tblnbsjProjectService.getSelectProject();
    	mv.addObject("project", project);
    	mv.addObject("orgid", orgid);
    	mv.setViewName("/nbsj/sjzb/projectDataPre_add");
    	//查询框代码
    	String choiceSearch = request.getParameter("choiceSearch");
    	if(choiceSearch == null || "".equals(choiceSearch)) {
    		choiceSearch = "hide";
    	}
    	mv.addObject("choiceSearch",choiceSearch); 
    	return mv;
    }
    /**
     *  审计项目资料
     * @return
     
    @RequestMapping(value="/sjzl/dataproject_save")
    public ModelAndView dataproject_add(HttpServletRequest request,TblProjectDataPreEntity dataPre){
    	ModelAndView mv=new   ModelAndView();
        TblStaff user = (TblStaff) request.getSession().getAttribute("longUser");
        if (dataPre.getId()==null) {
        	 dataPre.setUserName(user.getUsername());
		}
        //保存附件
        String attids = request.getParameter("attids");
        if (StringUtils.isNotBlank(attids)){
        	String[] ids = attids.split(",");
        	for (int i = 0; i < ids.length; i++) {
        		TblAttachmentEntity att = attachmentService.findById(ids[i].trim());
        		dataPre.getTblProjectDataPreAtts().add(att);
        	}
        }        
        dataPre.setDetaDate(new Date());
    	dataProService.updateTblProjectDataPre(dataPre);
    	String choiceSearch = request.getParameter("choiceSearch");
    	if(choiceSearch == null || "".equals(choiceSearch)) {
    		choiceSearch = "hide";
    	}
    	mv.setViewName("redirect:/nbsj/sjzl/dataproject_id?id="+dataPre.getId()+"&choiceSearch="+choiceSearch);
    	return mv;
    }
    
    
    @RequestMapping(value="/sjzl/dataproject_save",produces = "application/json; charset=utf-8")
    public @ResponseBody String savejudge(TblProjectDataPreEntity dataPre,HttpServletRequest request){
    	String id = request.getParameter("prid");
    	String projectDataPreId = request.getParameter("projectDataPreId");
        //保存附件
        String attids = request.getParameter("attids");
        if (StringUtils.isNotBlank(attids)){
        	String[] ids = attids.split(",");
        	for (int i = 0; i < ids.length; i++) {
        		TblAttachmentEntity att = attachmentService.findById(ids[i].trim());
        		dataPre.getTblProjectDataPreAtts().add(att);
        	}
        }
    	Integer proDataById=null;
    	if(id!=null&&id.trim().length()>0){
    	  proDataById = dataProService.proDataById(id);
    	}else{
    		  proDataById = dataProService.selectProjectNumber(projectDataPreId,dataPre.getProjectId());
    	}
    	if (proDataById==null || proDataById==0) {
    		 TblStaff user = (TblStaff) request.getSession().getAttribute("longUser");
    	     if (dataPre.getId()==null) {
    	     	 dataPre.setUserName(user.getUsername());
    		 }
    	     dataPre.setDetaDate(new Date());
    	     try {
				dataProService.saveOrUpdate(dataPre);
				return dataPre.getId().toString();
			} catch (Exception e) {
				e.printStackTrace();
				return "0";
			}
			
		}else {
			return "-1";
		}
    }
    
    
    /**
     *  审计项目资料
     * @return
     
    @RequestMapping(value="/sjzl/dataproject_id")
    public ModelAndView dataproject_id(String id,HttpServletRequest request){
    	ModelAndView mv=new   ModelAndView();
    	String prid = request.getParameter("id");
    	TblProjectDataPreEntity proDataById = dataProService.proDataById(new BigDecimal(prid));
    	mv.addObject("proDataById", proDataById);
    	mv.setViewName("/nbsj/sjzb/projectDataPre_update");
    	//查询框代码
    	String choiceSearch = request.getParameter("choiceSearch");
    	if(choiceSearch == null || "".equals(choiceSearch)) {
    		choiceSearch = "hide";
    	}
    	Set<TblAttachmentEntity> tblProjectDataPreAtts = proDataById.getTblProjectDataPreAtts();
    	String attids="";
    	if(null!=tblProjectDataPreAtts&&tblProjectDataPreAtts.size()!=0) {
    		Set<String> set = new HashSet<String>();
    		for (TblAttachmentEntity tblAttachment : tblProjectDataPreAtts) {
    			set.add(tblAttachment.getAttid().toString());
			}
    	       attids = String.join(", ", set);
    	}
    	mv.addObject("attids",attids); 
    	mv.addObject("choiceSearch",choiceSearch); 
    	return mv;
    }
    /**
     *  审计项目资料
     * @return
     
    @RequestMapping(value="/sjzl/dataproject_del")
    public  ModelAndView dataproject_del(String id,HttpServletRequest request){
    	ModelAndView mv=new ModelAndView();
    		TblProjectDataPreEntity dataPre = dataProService.proDataById(new BigDecimal(id));
    		dataProService.proDel(dataPre);
    		//查询框代码
    		String choiceSearch = request.getParameter("choiceSearch");
    		if(choiceSearch == null || "".equals(choiceSearch)) {
    			choiceSearch = "hide";
    		}
    		mv.addObject("choiceSearch",choiceSearch); 
    		mv.setViewName("redirect:/nbsj/sjzl/dataproject_list?orgid="+dataPre.getOrgid()+"&choiceSearch="+choiceSearch);
    	return mv;
    }
    /**
     *  审计项目资料
     * @return
     
    @RequestMapping(value="/sjzl/dataproject_view")
    public ModelAndView dataproject_view(String dataproid){
    	ModelAndView mv= new  ModelAndView();
    	TblProjectDataPreEntity proDataById = dataProService.proDataById(new BigDecimal(dataproid));
    	mv.addObject("proDataById", proDataById);
    	mv.setViewName("/nbsj/sjzb/projectDataview");
    	return mv;
    }
    /**
     * 审计项目资料-添加附件
     *
     * @param file
     * @param request
     * @param projectid
     * @param session
     * @return
     
    @RequestMapping(value = "/sjzl/dataproject_upload")
    public String dataproject_upload(MultipartFile file, HttpServletRequest request, String id, HttpSession session) {
//        logger.info("新建---添加附件");
        AttachmentService service = (AttachmentService) SpringContextHolder.getBean("AttachmentService");
        TblStaff user = (TblStaff) session.getAttribute("longUser");
        String fileName = file.getOriginalFilename();
        long size = file.getSize();
        long timeInMillis = Calendar.getInstance().getTimeInMillis();
		String oldname = fileName.substring(0,fileName.lastIndexOf("."));
		String newname=fileName.replace(oldname, timeInMillis+"sjxmzl");
		try {
			boolean flag = FtpUtil.uploadFile(newname, file.getInputStream());
			if(flag){
//				 logger.info("上传成功");
			}else{
//				 logger.info("上传失败");
			}
		} catch (Exception e) {
		    e.printStackTrace();
		}
        TblAttachmentEntity a = new TblAttachmentEntity();
        a.setAttname(fileName);
    	TblProjectDataPreEntity proData = new TblProjectDataPreEntity();        
    	proData.setId(Integer.valueOf(id));
        a.getTblProjectDataPre().add(proData);
        a.setAttpath(newname);
        a.setAttsize(new BigDecimal(size / 1024));
        a.setUploader(user.getUsername());
        a.setUploadtime(new Date());
        service.add(a);
        return "redirect:dataproject_id?id=" + id;
    }
    /**
     * 审计项目资料-删除附件
     *
     
    @RequestMapping(value = "/sjzl/dataproject_delete")
    public String dataproject_upload(HttpServletRequest request, String id, String attid) {
        if (StringUtils.isNotBlank(attid)) {
            AttachmentService service = (AttachmentService) SpringContextHolder.getBean("AttachmentService");
            service.delete(attid);
        }
        return "redirect:dataproject_id?id=" + id;
    }  
    
    
private static final String DOCDIC = PropertyFileReader.getItem("doc.path");
	
	/**
     * 审计通知书-列表
     *
     * @return
     
    @RequestMapping(value = "/sjzb/notice_list")
    public ModelAndView notice_list(HttpServletRequest request, String view, TblNbsjAdvicenoteEntity note) {
        String number = request.getParameter("pageNumber");
        Integer pageNumber = 1;
        if (number != null && number.length() > 0) {
            pageNumber = Integer.parseInt(number);
        }
        String pstartDates = request.getParameter("pstartDates");
        String pendDates = request.getParameter("pendDates");
        TblNbsjProjectEntity project = this.tblnbsjProjectService.getSelectProject();
        String projectId = request.getParameter("projectId");
        request.getSession().setAttribute("UETempType","sjtzs");
        if (projectId != null&&projectId.length()>0) {
        	project = tblnbsjProjectService.getById(projectId.toString());
	     }
        if (null != project) {
            pageBean = tblNbsjAdvicenoteService.findAll(project.getProjectId(), note, pstartDates, pendDates, pageNumber, pageBean.getPageSize());
        }else{
            setErrorJsp("001",request);
        }
        String identifier = null;
        try {
            identifier = activityPluginsService.getoNState(ProcessEnum.SJ_JHTZD.name());
        } catch (Exception e) {
            e.printStackTrace();
        }
        ModelAndView mv = new ModelAndView();
        mv.addObject("identifier",identifier);
        mv.setViewName("nbsj/sjzb/notice_list");
        mv.addObject("pageBean", pageBean);
        mv.addObject("pstartDate", pstartDates);
        mv.addObject("fication", request.getParameter("fication"));//项目归档返回          
        mv.addObject("pendDate", pendDates);
        mv.addObject("note", note);
        mv.addObject("view", view);
        mv.addObject("projectId", projectId);
      //查询框代码
        String choiceSearch = request.getParameter("choiceSearch");
        if(choiceSearch == null || "".equals(choiceSearch)) {
        	choiceSearch = "hide";
        }
        mv.addObject("choiceSearch",choiceSearch); 	
        return mv;
    }
    /**
     * 审计通知书--添加
     *
     * @return
     
    @RequestMapping(value = "/sjzb/notice_add")
    public ModelAndView notice_add(HttpServletRequest request) {
        ModelAndView mv = new ModelAndView();
        TblStaff user = (TblStaff) request.getSession().getAttribute("longUser");
        TblNbsjProjectEntity project = this.tblnbsjProjectService.getSelectProject();
        mv.setViewName("nbsj/sjzb/notice_add");
        mv.addObject("user", user);
        mv.addObject("project", project);
      //查询框代码
        String choiceSearch = request.getParameter("choiceSearch");
        if(choiceSearch == null || "".equals(choiceSearch)) {
        	choiceSearch = "hide";
        }
        mv.addObject("choiceSearch",choiceSearch); 	
        return mv;
    }
    /**
     * 审计通知书-编号是否存在
     *
     * @param request
     * @return
     
    @RequestMapping(value = "/sjzb/isnoteode")
    public
    @ResponseBody
    String isnoteode(HttpServletRequest request,TblNbsjAdvicenoteEntity note) {
        String code = request.getParameter("projectCode");
        String adviceid = request.getParameter("adviceid");
        String projectId = request.getParameter("projectid");
        //保存附件
        String attids = request.getParameter("attids");
        if (adviceid != null && adviceid.length() > 0) {
            TblNbsjAdvicenoteEntity newnote = tblNbsjAdvicenoteService.get(adviceid);
            String bodyinfo = request.getParameter("describe");
            if (bodyinfo != null && bodyinfo.trim().length() > 0) {
            	newnote.setContent(bodyinfo);
            }
            if (StringUtils.isNotBlank(attids)){
            	String[] ids = attids.split(",");
            	for (int i = 0; i < ids.length; i++) {
            		TblAttachmentEntity att = attachmentService.findById(ids[i].trim());
            		newnote.getTblNoteAtts().add(att);
            	}
            }             
            String advicename = request.getParameter("advicename");
            String des = request.getParameter("des");
            if(des!=null && des.length()>0){
            	newnote.setDes(des);
            }
            newnote.setAdvicename(advicename);
            tblNbsjAdvicenoteService.update(newnote);
            return note.getAdviceid().toString();
        }else{
        List<TblNbsjAdvicenoteEntity> list = tblNbsjAdvicenoteService.isNoteCode(code,projectId);
        if (list != null && list.size() > 0) {
            return  "-1";
        }else{
        	note.setCreatrtime(new Date());
            String bodyinfo = request.getParameter("describe");
            if (bodyinfo != null && bodyinfo.trim().length() > 0) {
                note.setContent(bodyinfo);
            }
            if (StringUtils.isNotBlank(attids)){
            	String[] ids = attids.split(",");
            	for (int i = 0; i < ids.length; i++) {
            		TblAttachmentEntity att = attachmentService.findById(ids[i].trim());
            		note.getTblNoteAtts().add(att);
            	}
            }             
            note.setProject(tblnbsjProjectService.getSelectProject());
            TblStaff user = (TblStaff) request.getSession().getAttribute("longUser");
            note.setTblCreater(user);
            note.setStatus(TblNbsjAdvicenoteEntity.NO_DEL);
            try {
				tblNbsjAdvicenoteService.save(note);
				return note.getAdviceid().toString();
			} catch (Exception e) {
				e.printStackTrace();
				return "0";
			}
        }
        }
        
    }
    @RequestMapping(value = "/sjzb/sjtzs_fileupload", produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String sjtzs_fileupload(MultipartFile advicenoteFile, HttpServletResponse response) {
        response.setCharacterEncoding("UTF-8");
//        logger.debug("HBFK----------------->开始上传文档");
        if (null == advicenoteFile) {
//            logger.debug("HBFK----------------->上传文件失败");
            return JsonBean.error("上传文件失败.");
        }
        String fileName = advicenoteFile.getOriginalFilename();
//        logger.debug("HBFK----------------->文档的名称:" + fileName);
        if (!fileName.endsWith("docx") && !fileName.endsWith("doc")) {
//            logger.debug("HBFK----------------->上传文件类型不正确,目前仅支持word文档");
            return JsonBean.error("上传文件类型不正确,目前仅支持word文档");
        }
        fileName = UUID.randomUUID().toString() + fileName.substring(fileName.lastIndexOf("."));
        try {
            /* String modulePath=request.getParameter("modulePath"); 
            String path = DOCDIC + "NBSJ/SJTZS/";
            String isOk = FileUtils.fileUpload(advicenoteFile, path, fileName);
            if (null != isOk) {
                return JsonBean.success(isOk + fileName);
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
//            logger.debug("HBFK----------------->" + e.getMessage());
            return JsonBean.error(e.getMessage());
        }
        return JsonBean.error("未知错误");
    }
    
    /**
     * 审计通知书-保存
     *
     * @param request
     * @param note
     * @return
     
    @RequestMapping(value = "/sjzb/sjtzs_save")
    public String sjzb_save(HttpServletRequest request, TblNbsjAdvicenoteEntity note) {
        note.setCreatrtime(new Date());
        String bodyinfo = request.getParameter("describe");
        if (bodyinfo != null && bodyinfo.trim().length() > 0) {
            note.setContent(bodyinfo);
        }
        note.setProject(tblnbsjProjectService.getSelectProject());
        TblStaff user = (TblStaff) request.getSession().getAttribute("longUser");
        note.setTblCreater(user);
        note.setStatus(TblNbsjAdvicenoteEntity.NO_DEL);
        tblNbsjAdvicenoteService.save(note);
        return "redirect:/nbsj/sjzb/notice_modify?selectid=" + note.getAdviceid();
    }
    /**
     * 审计通知书-查看
     *
     * @param request
     * @return
     
    @RequestMapping(value = "/sjzb/notice_disp")
    public ModelAndView notice_disp(HttpServletRequest request) {
        String selectid = request.getParameter("selectid");
        ModelAndView mv = new ModelAndView();
        if (selectid != null && selectid.length() > 0) {
            TblNbsjAdvicenoteEntity advicenote = tblNbsjAdvicenoteService.get(selectid);
            mv.addObject("note", advicenote);
        }
        mv.setViewName("nbsj/sjzb/notice_disp");
        return mv;
    }
    /**
     * 审计通知书--修改
     *
     * @return
     
    @RequestMapping(value = "/sjzb/notice_modify")
    public ModelAndView notice_modify(HttpServletRequest request) {

        String selectid = request.getParameter("selectid");
        ModelAndView mv = new ModelAndView();
        if (selectid != null && selectid.length() > 0) {
            TblNbsjAdvicenoteEntity advicenote = tblNbsjAdvicenoteService.get(selectid);
            mv.addObject("note", advicenote);
        }
        mv.setViewName("nbsj/sjzb/notice_modify");
      //查询框代码
        String choiceSearch = request.getParameter("choiceSearch");
        if(choiceSearch == null || "".equals(choiceSearch)) {
        	choiceSearch = "hide";
        }
        mv.addObject("choiceSearch",choiceSearch); 	
        return mv;
    }
    /**
      * @Author: TYB
      * @Date: 2017-02-23 下午 12:57
      * @Des: 审计通知书--提交审批
      
    @RequestMapping(value = "/sjtzs/submit_approval",produces = "application/json; charset=utf-8")
    public @ResponseBody String submit_approval(HttpServletRequest request,String selectid) {
        TblNbsjAdvicenoteEntity advicenote = tblNbsjAdvicenoteService.get(selectid);
        if(advicenote.getStatus()!=null && advicenote.getStatus()==2){
        	return JsonBean.error("目前正在审批中");
        }
        if(advicenote.getStatus()!=null && advicenote.getStatus()==4){
        	return JsonBean.error("审批已通过");
        }
        if(advicenote.getStatus()!=null && advicenote.getStatus()==5){
        	return JsonBean.error("审批已终止");
        }
        advicenote.setStatus(TblNbsjAdvicenoteEntity.SPZ);
        TblStaff user = (TblStaff) request.getSession().getAttribute("longUser");
        TblCirculation cir = tblCirculationService.saveTblCirculation(TblCirculation.TYPE_SJTZS,advicenote.getAdvicecoed()+"",advicenote.getAdvicename(),TblCirculation.URL_SJTZS+advicenote.getAdviceid(),user.getStaffid());
        try {
            processService.start(ProcessEnum.SJ_JHTZD.name(),user,cir);
            tblNbsjAdvicenoteService.update(advicenote);
        } catch (Exception e) {
            tblCirculationService.delTblCirculation(cir);
            e.printStackTrace();
            return JsonBean.error();
        }
        return JsonBean.success();
    }
    /**
     * @Author: TYB
     * @Date: 2017-02-23 下午 12:57
     * @Des: 审计通知书--再次提交审批
     
    @RequestMapping(value = "/sjtzs/resubmit_approval",produces = "application/json; charset=utf-8")
    public @ResponseBody String resubmit_approval(HttpServletRequest request,TblNbsjAdvicenoteEntity na) {
        String attids = request.getParameter("attids");
        TblNbsjAdvicenoteEntity advicenote = new TblNbsjAdvicenoteEntity();
        try {
            advicenote = tblNbsjAdvicenoteService.get(na.getAdviceid().toString());
            advicenote.setAdvicename(na.getAdvicename());
            String bodyinfo = request.getParameter("describe");
            advicenote.setContent(bodyinfo);
            advicenote.setDes(na.getDes());
            advicenote.setStatus(TblNbsjAdvicenoteEntity.SPZ);
            if (StringUtils.isNotBlank(attids)){
                String[] ids = attids.split(",");
                for (int i = 0; i < ids.length; i++) {
                    TblAttachmentEntity att = attachmentService.findById(ids[i]);
                    advicenote.getTblNoteAtts().add(att);
                }
            }
            tblNbsjAdvicenoteService.update(advicenote);
            String cyId = request.getParameter("cyId");
            TblCirculation c = tblCirculationService.get(cyId);
            c.setCyname(advicenote.getAdvicename());
            c.setCystate(TblCirculation.STATE_FQ);
            tblCirculationService.update(c);
        } catch (Exception e) {
            e.printStackTrace();
            return JsonBean.error();
        }
        return JsonBean.success();
    }

    /**
     * 审计通知书-修改-保存
     *
     * @param request
     * @param note
     * @return
     
    @RequestMapping(value = "/sjzb/sjtzs_modify")
    public String sjzb_update_save(HttpServletRequest request) {
        String adviceid = request.getParameter("adviceid");
        if (adviceid != null && adviceid.length() > 0) {
            TblNbsjAdvicenoteEntity note = tblNbsjAdvicenoteService.get(adviceid);
            String bodyinfo = request.getParameter("describe");
            if (bodyinfo != null && bodyinfo.trim().length() > 0) {
                note.setContent(bodyinfo);
            }
            String advicename = request.getParameter("advicename");
            String des = request.getParameter("des");
            note.setDes(des);
            note.setAdvicename(advicename);
            tblNbsjAdvicenoteService.update(note);
            return "redirect:/nbsj/sjzb/notice_modify?selectid=" + adviceid;
        }
        return "redirect:/nbsj/sjzb/notice_list";
    }
    /**
     * 审计通知书-删除
     *
     * @param request
     * @return
     
    @RequestMapping(value = "/sjzb/note_delete", produces = "application/json; charset=utf-8")
    public
    @ResponseBody
    String sjzb_delete(HttpServletRequest request) {
        String projectid = request.getParameter("projectid");
//        logger.info("项目--删除项目");
        if (projectid != null && projectid.length() > 0) {
            TblNbsjAdvicenoteEntity note = tblNbsjAdvicenoteService.get(projectid);
            note.setStatus(TblNbsjAdvicenoteEntity.YE_DEL);
            tblNbsjAdvicenoteService.update(note);
            return JsonBean.success();
        } else {
            return JsonBean.error("请选择删除的项目");
        }
    }
    /**
     * 审计通知书-添加附件
     *
     * @param file
     * @param request
     * @param projectid
     * @param session
     * @return
     
    @RequestMapping(value = "/sjzb/nbsj_note_upload")
    public String sjzb_note_upload(MultipartFile file, HttpServletRequest request, String adviceid, HttpSession session) {
//        logger.info("新建---添加附件");
        AttachmentService service = (AttachmentService) SpringContextHolder.getBean("AttachmentService");
        TblStaff user = (TblStaff) session.getAttribute("longUser");
        String fileName = file.getOriginalFilename();
        long size = file.getSize();
        long timeInMillis = Calendar.getInstance().getTimeInMillis();
		String oldname = fileName.substring(0,fileName.lastIndexOf("."));
		String newname=fileName.replace(oldname, timeInMillis+"sjtzs");
		try {
			boolean flag = FtpUtil.uploadFile(newname, file.getInputStream());
			if(flag){
//				 logger.info("上传成功");
			}else{
//				 logger.info("上传失败");
			}
		} catch (Exception e) {
		    e.printStackTrace();
		}
        TblAttachmentEntity a = new TblAttachmentEntity();
        a.setAttname(fileName);
        TblNbsjAdvicenoteEntity note = new TblNbsjAdvicenoteEntity();
        note.setAdviceid(new BigDecimal(adviceid));
//        a.getTblAttnotes().add(note);
        a.setAttpath(newname);
        a.setAttsize(new BigDecimal(size / 1024));
        a.setUploader(user.getUsername());
        a.setUploadtime(new Date());
        service.add(a);
        return "redirect:notice_modify?selectid=" + adviceid;
    }
    /**
     * 审计通知书-删除附件
     *
     * @param request
     * @param projectid
     * @param attid
     * @return
     
    @RequestMapping(value = "/sjzb/delete_note_upload")
    public String sjzb_note_upload(HttpServletRequest request, String noteid, String attid) {
        if (StringUtils.isNotBlank(attid)) {
            AttachmentService service = (AttachmentService) SpringContextHolder.getBean("AttachmentService");
            service.delete(attid);
        }
        return "redirect:notice_modify?selectid=" + noteid;
    }
    @RequestMapping(value = "/sjzb/auditobjective_add")
    public ModelAndView auditobjective_add() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("nbsj/sjzb/auditobjective_add");
        return mv;
    }
    @RequestMapping(value = "/sjzb/auditobjective_edit")
    public ModelAndView auditobjective_edit() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("nbsj/sjzb/auditobjective_edit");
        return mv;
    }
    @RequestMapping(value = "/wdcx/attachment_search")
    public ModelAndView attachment_search() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("nbsj/wdcx/attachment_search");
        return mv;
    }
    @RequestMapping(value = "/wdcx/doc_search")
    public ModelAndView doc_search() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("nbsj/wdcx/doc_search");
        return mv;
    }
    
    /**
	 * 审计通知书 邮件发送 选择相关人员
	 * @param request
	 * @return
	 
	@RequestMapping(value = "/user/emailUserIndex")
	public ModelAndView emailUserIndex(HttpServletRequest request) {
		ModelAndView mv = new ModelAndView("/nbsj/xmgl/emailUserIndex");
		String key = request.getParameter("key");
		mv.addObject("key", request.getParameter("key"));
		mv.addObject("val", request.getParameter("val"));
		return mv;
	}
	
	/**
	 * 审计通知书 邮件发送 选择相关人员-左侧tree
	 *
	 * @param request
	 * @return
	 
	@RequestMapping(value = "/user/emaillefts")
	public ModelAndView emailUserLefts(HttpServletRequest request) {
		TblOrganization attribute1 = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");// 当前用户的机构
		ModelAndView mv = new ModelAndView("/nbsj/xmgl/email_user_left");
		mv.addObject("orgid", attribute1.getOrgid());
		mv.addObject("targetFrame", "mainFramex");
		mv.addObject("key", request.getParameter("key"));
		mv.addObject("val", request.getParameter("val"));
		return mv;
	}
	
	/**
	 * 审计通知书 邮件发送 选择相关人员-组织架构
	 *
	 * @param nodeId
	 * @param type
	 * @param orgId
	 * @param request
	 * @return
	 
	@RequestMapping(value = "/findOrganizationByEmailTreeAll", produces = "application/json; charset=utf-8")
	public @ResponseBody String findOrganizationByEmailTreeAll(BigDecimal nodeId,BigDecimal orgId,
			HttpServletRequest request) {
			String json = "";
			String key = request.getParameter("key");
			String val = request.getParameter("val");
			if (null == nodeId) {
				nodeId = orgId;
				if (null == orgId) {
					TblStaff tblStaff = (TblStaff) request.getSession().getAttribute("longUser");
					nodeId = tblStaff.getTblOrganization().getOrgid();
				}
			}
			// 修改前 Tree tree = this.tblOrganizaService.getTreeRoot(nodeId);
			// tyb修改 项目管理--/项目经理展开左侧树
			List<Tree> list = this.tblOrganizaService.getNodeAll(nodeId);
			for (Tree tree : list) {
				setUrlByTree(tree, "/nbsj/user/emaillist?&type=1&key=" + key + "&val="+val+"&pid=");
			}
			json = JSONObject.toJSONString(list);
		return json;
	}
	
	/**
     * 审计指引  --- 模板
     * <p>Title:</p>
     * <p>Description:</p>
     *
     * @author SongXiangYing
     * @date 2016年9月7日 下午1:45:51
     
    @RequestMapping(value = "/sjgj/template_list_zy")
    public ModelAndView template_list_zy(String templeteName, String templeteCode, Integer status, Integer pageNumber,HttpServletRequest request) {
        ModelAndView mv = new ModelAndView();
        pageBean = this.tblNbsjTempleteService.findTemplete(templeteName, templeteCode, status, TblNbsjTempleteEntity.ZY_TYPE, pageNumber, pageBean.getPageSize());
        mv.setViewName("nbsj/sjgj/template_list_zy");
        mv.addObject("pageBean", pageBean);
        mv.addObject("templeteName", templeteName);
        mv.addObject("templeteCode", templeteCode);
        mv.addObject("status", status);
      //查询框代码
        String choiceSearch = request.getParameter("choiceSearch");
        if(choiceSearch == null || "".equals(choiceSearch)) {
        	choiceSearch = "hide";
        }
        mv.addObject("choiceSearch",choiceSearch); 
        return mv;
    }
    
    
    
	
	
	
	
	
	
	private void setUrlByTree(Tree tree,String url){
        for (Tree tre : tree.getChildren()){
            if (tre.getChildren().size()>0){setUrlByTree(tre,url);}
           // if (!tre.getIsParent()) {
                tre.setTarget("mainFramex");
                tre.setUrl(url+tre.getId());
            //}
        }
    }
    
    /**
     * @Author: TYB
     * @Date: 2017-04-10 下午 1:19
     * @Des: 后台报错跳转error页时传递提示
    *  data:001:未选择项目  002:项目未添加指引模板
    
   	public void setErrorJsp(String data,HttpServletRequest request){
   		request.getSession().removeAttribute("ErrorJsp");
   		request.getSession().setAttribute("ErrorJsp",data);
   	}*/
}
